<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            width: 300px;
            height: 300px;
            border: 1px solid #0f0;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            align-items: center;
            list-style: none;
        }

        li {
            width: 30%;
            height: 30%;
            background-color: #ff0;
            text-align: center;

        }

        .active {
            background-color: hotpink;
        }
    </style>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li class="active">9</li>
    </ul>
    <button>随机奖品位置</button>
</body>
<script>
    var btn = document.querySelector("button")
    var lis = document.querySelectorAll("li")
    // var num=parseInt(Math.random()*9)+1
    // console.log(num);
    // console.log(parseInt(2.5));

    btn.onclick = () => {
        var num = parseInt(Math.random() * 9)
        for (let i = 0; i < lis.length; i++) {
            lis[i].className = ""



        }
        console.log(num);
        if (num !== 4) {
            lis[num].className = "active"

        }
    }
    let arr = [
        { id: 1, name: '部门1', pid: 0 },
        { id: 2, name: '部门2', pid: 1 },
        { id: 3, name: '部门3', pid: 1 },
        { id: 4, name: '部门4', pid: 3 },
        { id: 5, name: '部门5', pid: 4 },
    ]


    function fn(arr) {
       
        arr.forEach((item, index) => {

            item.children=[]
        })
        console.log(arr);
    }
    fn(arr)
</script>

</html>